import java.util.Arrays;

public class t1562 {//查找大小为M的最新分组
    //暴力枚举 102/114超时
    public static void main(String[] args) {
        int arr[] = {3,5,1,2,4};
        int m =1;
        int num = findLatestStep(arr,m);
        System.out.println(num);
    }

    public static int findLatestStep(int[] arr, int m) {
        int k = -1;
        char crr[] = new char [arr.length];
        Arrays.fill(crr,'0');
        String str = "";
        for(int i =0;i<arr.length;i++){
            int a = arr[i];
            crr[a-1] = '1';
            str = new String(crr);
            String tmp[] = str.split("[0]+");
            for(String s : tmp) {
                if(s.length() == m){
                    k = i+1;
                    break;
                }
            }
        }
        return k;
    }

}
